{layout name="layout" /}

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i>
    <a href="{:url('admin/index/index')}"> 首页</a>
    <span class="c-gray en">&gt;</span>
    <a href="{:url('admin/data_content/index')}">数据内容管理</a>
    <span class="c-gray en">&gt;</span>
    <a href="javascprit:;">{$tablename} - {$data.id ? '修改' : '新增'}</a>
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
        href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>

<div class="Hui-article">
    <article class="cl pd-20">
        <form action="{:url('doAddOrEditinfo',['id'=>$data.id,'tablename'=>$tablename])}" method="post"
            class="form form-horizontal" id="form-admin-category" enctype="multipart/form-data">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>标题：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" value="{$data.title}" placeholder="请填写图片标题" id="title" name="title">
                </div>
                <div class="col-3"> </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    点击量：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="number" class="input-text" value="{$data.clicks}" id="clicks" name="clicks">
                </div>
            </div>
            {foreach $table_extra_columns as $value}
            {php}
            if ($value->column_name_en == 'remark') {
            continue;
            }
            {/php}
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    {$value.column_name_cn}：</label>
                    <div class="formControls col-xs-4 col-sm-4">
                        {eq name='value.column_name_en' value="file"}
                        <input type="text" class="input-text" value="{$data[$value.column_name_en]}" name="{$value.column_name_en}">
                        <input type="file" name="upload_file" id="upload_file">
                        {else/}
                        <input type="text" class="input-text" value="{$data[$value.column_name_en]}"
                        placeholder="请填写{$value.column_name_cn}" id="{$value.column_name_en}"
                        name="{$value.column_name_en}">
                        {/eq}
                    </div>
                <div class="col-xs-4 col-sm-4 text-l">
                    {$value.note}</div>
                <div class="col-3"> </div>
            </div>
            {/foreach}
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">备注：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <textarea name="remark" id="remark" cols="" rows="" class="textarea" placeholder="说点什么...最多输入100个字符"
                        datatype="*10-100" dragonfly="true" onKeyUp="textarealength(this,200)">{$data.remark}</textarea>
                    <p class="textarea-numberbar">
                        <em class="textarea-length">0</em>/200</p>
                </div>
                <div class="col-3"> </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <button type="submit" class="btn btn-success radius" id="admin-picturedata-save">确&nbsp;定</button>
                    <button type="button" class="btn btn-default radius" onclick="window.history.back();"
                        style="margin-left:20px;">取&nbsp;消</button>
                </div>
            </div>
        </form>
        
    </article>
</div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $("#form-admin-category").submit(function () {
        var note = $("#note").val();
        if (getblen(note) > 200) {
            layer.msg('备注过长', {
                icon: 5,
                time: 1000
            });
            return false;
        }
    })
    function uploadImg() {
        var imgNum = $("#imgNum").val();
        if ($("#upload_file").val() == '') {
            layer.msg("请选择要上传的文件", {
                icon: 6,
                time: 1000
            });
            return false;
        } else {
            var formData = new FormData($("#form-upload")[0]);
            //ajax上传
            $.ajax({
                url: '/admin/file_manager/uploadimg',
                type: 'POST',
                async: true,
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function (data) {
                    // console.log(data);
                    if (data.code == 2) {
                        imgNum++;
                        // img = data.data;
                        var img_str = '';
                        img_str += '<div class="row cl" id="num_' + imgNum + '">';
                        img_str += '<label class="form-label col-xs-2 col-sm-2">' + imgNum +
                            '&nbsp;&nbsp;&nbsp;&nbsp;缩略图:</label>';
                        img_str += '<div class="formControls col-xs-3 col-sm-3">';
                        img_str += '<input type="text" class="input-text thumb" value="' + data.thumbname +
                            '" placeholder="" id="thumb_' + imgNum + '" name="thumb[]"></div>';
                        img_str += '<label class="form-label col-xs-1 col-sm-1">大图:</label>';
                        img_str += '<div class="formControls col-xs-3 col-sm-3">';
                        img_str += '<input type="text" class="input-text pic" value="' + data.picname +
                            '" placeholder="" id="pic_' + imgNum + '" name="pic[]"></div>';
                        img_str += '<div class="formControls col-xs-2 col-sm-2">';
                        img_str +=
                            '<a href="javascript:void(0);" class="btn btn-success radius" onClick="deleteImg(' +
                            imgNum + ')">删除</a></div></div>';
                        $("#tuji").append(img_str);
                        $("#imgNum").val(imgNum)
                        $("#form-upload")[0].reset();
                    } else {
                        layer.msg(data.msg);
                        return false;
                    }
                }
            });
        }
    }

    function deleteImg(num) {
        layer.confirm('确认要删除吗？', function (index) {
            var filename = [$('#thumb_' + num).val(), $('#pic_' + num).val()];
            // console.log(filename);
            // return false;
            $.post('/admin/file_manager/delete', {
                'filename': filename
            }, function (data) {
                if (data.code == 1) {
                    // console.log(data);
                    $('#num_' + num).remove();
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 5,
                        time: 2000
                    });
                    return false;
                }
            }, 'json');
        });
    }
</script>